﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Inventory.InputInventory;
using WindowsForms.AOnline.View.Inventory;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Voucher
{
    public partial class UserControlInputInventoryList : BaseVoucherListUserControl, IItemTransactionsView 
    {
        /// <summary>    
        /// The _payment vouchers presenter
        /// </summary>
        private readonly InputInventoriesPresenter _inputInventoriesPresenter;
        public UserControlInputInventoryList()
        {
            InitializeComponent();
            _inputInventoriesPresenter = new InputInventoriesPresenter(this);  
        }

        public IList<Model.BusinessObjects.Inventory.ItemTransactionModel> ItemTransactions
        { 
            set
            {
                ColumnsCollection.Clear();
                bindingSource.DataSource = value;
                gridView.PopulateColumns(value);
                foreach (var itemTransactionModel in value)
                {
                    itemTransactionModel.TotalAmountOc = itemTransactionModel.TotalAmountOc +
                                                         itemTransactionModel.TotalAmountTax;
                }
                ColumnsCollection.Add(new XtraColumn { ColumnName = "ItemTransactionDetails", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "RefId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsCalculatePrice", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "TaxCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "TotalAmountTax", ColumnVisible = false });


                ColumnsCollection.Add(new XtraColumn { ColumnName = "RefTypeId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AccountingObjectType", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "CustomerId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "VendorId", ColumnVisible = false });
              //  ColumnsCollection.Add(new XtraColumn { ColumnName = "EmployeeId", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Trader", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "StockId", ColumnVisible = false });
            //    ColumnsCollection.Add(new XtraColumn { ColumnName = "ExchangeRate", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DocumentInclude", ColumnVisible = false });
            //    ColumnsCollection.Add(new XtraColumn { ColumnName = "ObjectId", ColumnVisible = false });
            //    ColumnsCollection.Add(new XtraColumn { ColumnName = "PostedDate", ColumnCaption = "Ngày HT", ToolTip = "Ngày hạch toán", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 70, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "RefNo", ColumnCaption = "Số CT", ToolTip = "Số chứng từ", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 70 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "RefDate", ColumnCaption = "Ngày CT", ToolTip = "Ngày chứng từ", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 70, Alignment = HorzAlignment.Center });
            //    ColumnsCollection.Add(new XtraColumn { ColumnName = "CurrencyCode", ColumnCaption = "Loại tiền tệ", ColumnPosition = 4, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "JournalMemo", ColumnCaption = "Diễn giải", ColumnPosition = 5, ColumnVisible = true, ColumnWith = 200 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "TotalAmountOc", ColumnCaption = "Tổng tiền", ColumnPosition = 6, ColumnVisible = true, ColumnWith = 150, ColumnType = UnboundColumnType.Decimal, Alignment = HorzAlignment.Far });
           //     ColumnsCollection.Add(new XtraColumn { ColumnName = "TotalAmountExchange", ColumnCaption = "Tổng tiền quy đổi", ColumnPosition = 7, ColumnVisible = true, ColumnWith = 150, ColumnType = UnboundColumnType.Decimal });
            }
        }
        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoGrid(int page)
        {

            TotalPage = _inputInventoriesPresenter.GetPageSize((int)RefTypeId);
            if (page <= TotalPage)
            {
                _inputInventoriesPresenter.Display((int)RefTypeId,page);
            }
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteGrid()
        {
          return  new InputInventoryPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }
    }
}
